package com.sjq.yqgl.web;

import java.util.Map;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;
import com.sjq.common.web.SessionUserHelper;
import net.sf.json.JSONObject;
import com.sjq.common.entity.Result;
import com.sjq.common.entity.LoginAccount;
import com.sjq.common.service.UserService;
import org.springframework.web.multipart.commons.CommonsMultipartFile;
import com.sjq.yqgl.service.YqbsService;
import com.sjq.yqgl.entity.Yqbs;
import com.sjq.common.util.PageResults;

@Controller
public class YqbsController {
	@Autowired
    private YqbsService yqbsService;
    @Autowired
    private HttpSession session;  
    private static final String INITURL = "yqbs/"; 
   /**查询列表***/
   @RequestMapping(INITURL+"YqbsList")
   @ResponseBody
   public JSONObject  YqbsList(Integer pageNo, Integer pageSize, Yqbs yqbs){
 	  if(yqbs==null){
    		yqbs=new Yqbs();
    	}
 	  SessionUserHelper helper = SessionUserHelper.createBySession(session);
      LoginAccount la= helper.getLoginAccount();
      String role=la.getUserRole();
   	   if(role.equals("0001")){
   		   
   		   
   	   }else  if(role.equals("0002")){
   		   //分县局上报
   		   yqbs.setDjrjh(la.getAccountId());
   		   
   	   }
   	   pageNo = pageNo == null ? 1 : pageNo;
       PageResults<?> pageResults=yqbsService.findYqbsByPage(pageNo, PageResults.ALLPAGESIZE, yqbs);
       JSONObject json=new JSONObject();
       json.put("dataList", pageResults.getResults());
       json.put("pageNo",  pageResults.getPageNo());
       json.put("pages", pageResults.getPageCount());
       return json;
   }
   
    /**提交表单---不含文件**/
    @RequestMapping(INITURL+"addYqbs")
	@ResponseBody
	 public JSONObject addYqbs(Yqbs yqbs) {
	   SessionUserHelper helper = SessionUserHelper.createBySession(session);
       LoginAccount la= helper.getLoginAccount();
       return yqbsService.addYqbs(yqbs, la);
    }
    
    /**提交表单---含附件**/
    @RequestMapping(INITURL+"addYqbsFiles")
	 public ModelAndView addYqbsFiles(Yqbs yqbs,@RequestParam("fj") CommonsMultipartFile[]  fj) {
	   SessionUserHelper helper = SessionUserHelper.createBySession(session);
       LoginAccount la= helper.getLoginAccount();
       yqbsService.addYqbsFilesByFTP(yqbs,fj, la);
       ModelAndView mav=new ModelAndView();
	   mav.setViewName("/view/common/ok");
	   return mav;
    }
    /**删除信息**/
     @RequestMapping(INITURL+"deleteYqbs")
	 @ResponseBody
	 public JSONObject deleteYqbs(String yqbsId) {
        SessionUserHelper helper = SessionUserHelper.createBySession(session);
        LoginAccount la= helper.getLoginAccount();
        return yqbsService.deleteYqbs(yqbsId,la);
    }	
    
    
    /**更新表单**/
     @RequestMapping(INITURL+"motifyYqbs")
	 @ResponseBody
	 public JSONObject motifyYqbs(Yqbs yqbs) {
        SessionUserHelper helper = SessionUserHelper.createBySession(session);
        LoginAccount la= helper.getLoginAccount();
        return  yqbsService.updateYqbs(yqbs,la);   
    }	
    
    
     /**
    * @description 根据查询条件查询表的所有详细信息
    **/
	@RequestMapping(INITURL+"findYqbsAllList")
    @ResponseBody
    public JSONObject  findYqbsAllList(Yqbs yqbs){
 		   SessionUserHelper helper = SessionUserHelper.createBySession(session);
       	   LoginAccount la= helper.getLoginAccount();
		   return  yqbsService.findYqbsByListAll(yqbs,la);  	
     }
   
   
}
